package com.ikas.ai;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 线程基类
 * @author HXH
 */
public class BaseThread extends Thread {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    /** 是否终止 */
    protected volatile boolean isTerminate = false;

    @Override
    public void run() {
        throw new UnsupportedOperationException();
    }

    /**
     * 终止接收数据线程
     */
    public synchronized void terminate() {
        if (!this.isTerminate) {
            this.isTerminate = true;
            logger.debug(this.getName() + " is terminate.");
        } else {
            logger.debug(this.getName() + " is already terminated.");
        }
    }
}
